﻿import cn.eminia.A2.utils.uMC;
import cn.eminia.A2.btnEffect.BEV3;
import cn.eminia.A2.utils.uPos;
import cn.eminia.A2.utils.uTween;
import mx.utils.Delegate;
import cn.eminia.A2.utils.uString; 
import mx.utils.ObjectCopy;
import mx.transitions.Tween;
import mx.transitions.easing.*;
import com.darronschall.DynamicRegistration;
import gs.*; 
import cn.eminia.A2.HandDoBtn;

import flash.geom.Rectangle;
import cn.eminia.A2.ui.style.PanelStyle;

/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.ui.cluePannelV2 extends cn.eminia.A2.ui.Pannel
{
	var btnPart	:MovieClip;
	var tfPart	:MovieClip;
	var tf		:TextField;
	var btn_ruler	:MovieClip;
	var btn_real	:MovieClip;
	var scope	:MovieClip;
	var ntf		:MovieClip;
	var bg		:MovieClip;
	
	var btn_arr	:Array = [];
	var func_arr:Array = [];
	var autoClose_arr:Array = [];
	var callback:Function; 
	var iconCtnr:MovieClip;
	var mode:String;
	
	
	var btnID:Number;
	//傀儡
	var tempArr:Array
	
	
	public function cluePannelV2 () 
	{
		super();
		
		tf.multiline = true;
		tf.selectable 	= false;
		btn_ruler 		= btnPart.ruler; 	
		
	} 

	//this._visible = false; 
 
	function show(scope:MovieClip, str:String, btnSet:String, last_one:Object) { 		
		
		this.scope = (scope != null)? scope:null;
		trace(this.scope)
		if (this.scope == null) throw new Error( "!! cn.eminia.A2.ui.cluePannelV2::show 缺少scope");
		 
		
		var arg_arr:Array = arguments;
		
		var vars:Object = new Object();
		// 当有4个参数的时候，说明是带按钮的
		if(arg_arr.length>2){
			vars = ObjectCopy.copy(last_one);
			this.callback = (last_one.callback != null)?last_one.callback:null;   
			 
			 var btnArr:Array 	= [];    
			 
			 // 分解btnSet的字符串设置
			if ( -1 == btnSet.indexOf("|")) { 
				 btnArr.push	(btnSet); 
			}else { 
				var tempArr:Array = btnSet.split("|")
				//排除掉最后一个索引值,作为默认按钮索引
				if (!isNaN(tempArr[tempArr.length-1])) {
					btnID = Number(tempArr[tempArr.length - 1]); 
					tempArr.pop();
				}else {
					btnID = null;
				}
				//将剩余值组成按钮ID
				for (var i:Number = 0; i < tempArr.length; i++) 
				{
					var oo:String = tempArr[i];
					btnArr.push	(oo);  
				}
			} 
		}
		
		cn.eminia.A2.btnEffect.uBtn.del(this);
		removeMovieClip(btn_real);
		btn_real 		= btnPart.createEmptyMovieClip('real',1); 
				 
	//------------------------  华丽的分割线 --------------------------  文本
		tf.text = uString.replace(str, '`', '\r'); 
		 
		if(this.mode =="returnVV"){ 
			var now_dele:MovieClip = uMC.newMC(ntf);
		}else { 
			ntf = this.createEmptyMovieClip('ntf', 9999);
			ntf._x = tf._x;
			ntf._y = tf._y;
			var now_dele:MovieClip = uMC.newMC(ntf); 
		}
		cn.eminia.A2.utils.uBitmap.bmTxt(tf, now_dele);		
		//cn.eminia.A2.utils.uBitmap.bmTxt(tf);		
		
		if (last_one.style != null) { 
			trace("ClueID = "+ _____CONTENT_____ )
			//PanelStyle.setBg(this.bg,,last_one.style);
		}
		
	//------------------------  华丽的分割线 --------------------------  按钮 
		 
		 this.btn_arr 		= []; 
		 
		var realNum:Number 	= 0;
		var len:Number 	= btnArr.length;
		var Xpos:Number 	= 0;
		 
		
		for (var i:Number = 0; i < len; i++) 
		{
								
			var b = btn_real.attachMovie(btnArr[i], i.toString(), i); 
			if (b != null) {
				/*
				if (b.constructor == Button) {
					
					//trace( "注意!! cn.eminia.A2.ui.cluePannelV2::show 所附加的MC是Button");
					
				}
				*/
				realNum++;
				b._x += Xpos;
				Xpos += b._width + 30;				
				
				btn_arr.push(b);
				b.label=btnArr[i]
				new BEV3(this, b,function(evt) {  
						evt['idt'] = evt.it.label;
						trace('this.callback - > '+this.callback);
						Delegate.create(this.scope, this.callback)(evt); 
						cn.eminia.A2.btnEffect.uBtn.dummy(this);
						close();						 
					}
					
				) 
			}else {
				throw new Error( "附加失败!! cn.eminia.A2.ui.cluePannelV2::show 请检查库链接 -> "+btnArr[i]);
			}
		}
		if (this.mode == 'wait') {			
			if (iconCtnr != null && iconCtnr._alpha > 0) {
					uTween.fadeOut(iconCtnr)
			}
			this.mode = 'returnVV';
		}
		if (vars.loadingIconID != null) {
			var dd:Number = this.getNextHighestDepth();
			iconCtnr = this.attachMovie(vars.loadingIconID, dd.toString(), dd);   
			if (iconCtnr != null) { 
				uPos.center(this.bg, this.iconCtnr);
				if (vars.loadingIconOffset != null) {
						 this.iconCtnr._x += vars.loadingIconOffset[0];
						 this.iconCtnr._y += vars.loadingIconOffset[1];
				}
				this.mode = 'wait';
			}else 
			{
				throw new Error( "附加失败!! cn.eminia.A2.ui.cluePannelV2::show 请检查库链接 -> " + iconCtnr);
			} 
				
		}
		//Pos.centerMutiple(btn_ruler, btn_arr ); 
		
																	// 居中对齐
		uPos.center(btn_ruler, btn_real);
		btn_ruler._visible = false;
		 
		trace("this.mode = " + this.mode );
		if (this.mode == 'returnVV') { 
			this.mode = null;
		}else {
			this.open(true);	
		}
		 
	} 
	
}